#include <iostream>
#include <string>
#include <vector>

#include "sqlite.hpp"
using namespace std;
using namespace NS_SQLiteHepler;

int SqlCallback(void *arg, int col_num, char **col_data, char **col_name)
{
    vector<vector<string>> *array = static_cast<vector<vector<string>> *>(arg);

    if (array->empty())
    {
        vector<string> tmp;
        for (int i = 0; i < col_num; i++)
        {
            tmp.push_back(col_name[i]);
        }
        array->push_back(tmp);
    }

    vector<string> tmp;
    for (int i = 0; i < col_num; i++)
    {
        tmp.push_back(col_data[i]);
    }
    array->push_back(tmp);

    // 返回0是必须的
    return 0;
}

int main()
{
    SQLite3Helper helper("./student");
    helper.open();

    // 创建表
    // helper.insert("create table if not exists student(id int primary key, name varchar(32), age int);");

    // 插入数据
    // helper.insert("insert into student values(1, '张三', 20), (2, '李四', 18), (3, '王五', 19);");

    // 删除数据
    // helper.erase("delete from student where id=3;");

    // 修改数据
    // helper.update("update student set name='赵六' where id=2;");

    // 查看数据
    vector<vector<string>> array;
    helper.select<vector<vector<string>>>("select * from student", SqlCallback, array);

    for(const auto& e : array)
    {
        for(const auto& s : e)
        {
            cout << s << " ";
        }
        cout << endl;
    }

    return 0;
}